#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
	int q;
	scanf("%d", &q);
	char str[1000] = { 0 };
	scanf("%s", str);
	int a = 0, b = 0;
	char st[101][101] = { 0 };
	for (int i = 0; i < q; i++)
	{
		fgets(st[i], 100, stdin);
	}
	for (int i = 0; i < q; i++)
	{
		if (st[i][0] == '1')
		{
			strcat(str, str[i]);
			printf("%s", str);
		}
		if (st[i][0] == '2')
		{
			int m = 0;
			for (int x = 2;; x++)
			{
				if (st[i][x] >= '0' && st[i][x] <= '9')
				{
					a = a * 10 + st[i][x] - 48;
				}
				if (st[i][x] == ' ')
				{
					m = x; break;
				}
			}
			for (int l = m + 1;; l++)
			{
				if (st[i][l] >= '0' && st[i][l] <= '9')
				{
					b = b * 10 + st[i][l] - 48;
				}
				else break;
			}
			char p[100] = { 0 };
			for (int t = 0; t < b; t++)
			{
				p[t] = str[a + t];
			}
			strcpy(str, p);
			printf("%s", str);
		}
		if (st[i][0] == '3')
		{
			int m;
			a = 0;
			for (int x = 2;; x++)
			{
				if (st[i][x] >= '0' && st[i][x] <= '9')
				{
					a = a * 10 + st[i][x] - 48;
				}
				if (st[i][x] == ' ')
				{
					m = x + 1;
					break;
				}
			}
			int len = strlen(st[i]) - m;
			for (int l = 0; l < len; l++)
			{
				str[a + len + l + 1] = str[a + l];
			}
			printf("%s", str);
		}
		if (st[i][0] == '4')
		{
			int k = 0;
			strcpy(st[i], st[i] + 2);
			for (int w = 0; w < strlen(str); w++)
			{
				if (st[i][0] == str[w])
				{
					for (int h = 0; h < strlen(st[i]); h++)
					{
						if (st[h] != str[w + h])
						{
							break;
						}
						if (k != -1)
						{
							k = w;
							printf("%d", k);
							break;
						}
					}
				}
			}
			if (k == 0)
				printf("-1");
		}
	}

	return 0;
}
